using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using razor教程.Data;
using razor教程.Models;

namespace razor教程.Pages
{
    public class CreateModel : PageModel
    {
        private readonly RazorContext _context;

        public CreateModel(RazorContext context)
        {
            _context = context;
        }

        [BindProperty]
        public Customer Customer { get; set; }

      

        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            _context.Customers.Add(Customer);
            await _context.SaveChangesAsync();
            return RedirectToPage("/index");
        }
    }
}
